perm filename LINFIT.F4[NET,GUE]1 blob
sn#026503 filedate 1973-02-27 generic text, type T, neo UTF8
SUBROUTINE LINFIT
COMMON /FIT/X,Y,SIGMAY,NPTS,MODE,A,SIGMAA,B,SIGMAB,R,SCALEX,SCALEY
INTEGER NPTS,MODE
DOUBLE PRECISION X,Y,SIGMAY,A,SIGMAA,B,SIGMAB,R
DOUBLE PRECISION SUM,SUMX,SUMY,SUMX2,SUMXY,SUMY2
DOUBLE PRECISION XI,YI,WEIGHT,DELTA,VARNCE,SCALEX,SCALEY
DIMENSION X(50),Y(50),SIGMAY(50)
11 SUM=0.
SUMX=0.
SUMY=0.
SUMX2=0.
SUMXY=0.
SUMY2=0.
21 DO 50 I=1,NPTS
XI=X(I)/SCALEX
YI=Y(I)/SCALEY
IF (MODE) 31,36,38
31 IF (YI)34,36,32
32 WEIGHT=1./YI
GOTO 41
34 WEIGHT=1./(-YI)
GOTO 41
36 WEIGHT=1.
GOTO 41
38 WEIGHT=1./SIGMAY(I)**2
41 SUM=SUM+WEIGHT
42 SUMX=SUMX+WEIGHT*XI
SUMY=SUMY+WEIGHT*YI
SUMX2=SUMX2+WEIGHT*XI*XI
SUMXY=SUMXY+WEIGHT*XI*YI
SUMY2=SUMY2+WEIGHT*YI*YI
50 CONTINUE
51 DELTA=SUM*SUMX2-SUMX*SUMX
A=(SUMX2*SUMY-SUMX*SUMXY)/DELTA
B=(SUMXY*SUM-SUMX*SUMY)/DELTA
61 IF (MODE)62,64,62
62 VARNCE=1.
GOTO 67
64 C=NPTS-2
VARNCE=(SUMY2+A*A*SUM+B*B*SUMX2-2.*(A*SUMY+B*SUMXY-A*B*SUMX))/C
67 SIGMAA=DSQRT(VARNCE*SUMX2/DELTA)
68 SIGMAB=DSQRT(VARNCE*SUM/DELTA)
71 R=(SUM*SUMXY-SUMX*SUMY)/(DSQRT(DELTA)*DSQRT(SUM*SUMY2-SUMY*SUMY))
A=A*SCALEY
SIGMAA=SIGMAA*SCALEY
B=B*SCALEY/SCALEX
SIGMAB=SIGMAB*SCALEY/SCALEX
RETURN
END